package com.zby.converter;

import com.zby.model.enums.BaseEnum;
import org.dromara.autotable.core.constants.DatabaseDialect;
import org.dromara.autotable.core.converter.DefaultTypeEnumInterface;
import org.dromara.autotable.core.converter.JavaTypeToDatabaseTypeConverter;
import org.dromara.autotable.core.strategy.mysql.data.MySqlDefaultTypeEnum;
import org.springframework.stereotype.Component;

import java.lang.reflect.Field;

@Component
public class MyJavaTypeToDatabaseTypeConverter implements JavaTypeToDatabaseTypeConverter {
    @Override
    public DefaultTypeEnumInterface getSqlType(String databaseDialect, Class<?> clazz, Field field) {
        if (databaseDialect.equals(DatabaseDialect.MySQL) && BaseEnum.class.isAssignableFrom(field.getType())) {
            return MySqlDefaultTypeEnum.TINYINT;
        }
        return JavaTypeToDatabaseTypeConverter.super.getSqlType(databaseDialect, clazz, field);
    }
}
